Skip to content

WO20: megaregexp replacement build, deferred re-only tos, undefined-ref drops — reverse shrink-to-zero - #868

Merged
ronaldtse merged 2 commits into
mainfrom
wo20-reverse-engine-fixes
Nov 18, 2026
Merged

ronaldtse merged 2 commits into
mainfrom
wo20-reverse-engine-fixes

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

The ruby side of the WO20 reverse-golden shrink-to-zero (rs PR wo20-reverse-shrink-to-zero is the reference side; merge that first — it carries the grown golden this replay consumes).

Three engine fixes in the megaregexp parallel pass, each closing a divergence family:

  • Replacement build: :str semantics (rs build_replacement parity) instead of the :parstr array product build that stringified arrays into the output (odni-pus family). The WO18 G1 canon (ref template in parallel fails loud and named) is pinned by an explicit guard — spec/isc/semantics_spec.rb unchanged and green.
  • Deferred re-only tos: rs renders replacements lazily (only when a rule fires); a boundary hoisted onto a reversed to no longer kills the whole pass when the rule never matches (bgnpcgn-per / un-prs family, 32 null rows).
  • Undefined-ref drops: a from-pattern \N to a group the pattern does not define can never match (rs semantics) — the rule now drops from the alternation instead of failing the combined compile (bgnpcgn-zho family).

With this branch plus the rs golden, the full reverse replay is 0 deltas on 15,321 rows / 452 maps.

Test plan

  • bundle exec rake spec: 546 examples, 106 failures — failure set byte-identical to pristine origin/main (verified by diff; those 106 are pre-existing environment failures)
  • Reverse golden replay vs rs wo20-reverse-shrink-to-zero: 15,321 rows, 0 delta maps
  • maps-CI additivity gates (ruby reverse step) on the merged state

…ed-ref drops - WO20 reverse shrink-to-zero

Three engine fixes closing the ruby side of the WO20 reverse-golden
divergence families (rs PR wo20-reverse-shrink-to-zero is the reference
side; with these the full 15,321-row reverse replay is 0-delta):

- Megaregexp replacements now carry the STRING build (`build_item(:str)`
  - groups join, captures parenthesize, refs become backrefs), which is
  what rs `build_replacement` renders over the nth_string collapse.
  `build_item(:parstr)` demotes to the :par product build and returns
  ARRAYS for group `to`s, which gsub stringified as Ruby inspect into
  the output (odni-pus `Aبد[" اللَّه"]`). The WO18 G1 canon - a ref
  template in a parallel pass fails loud and named - is pinned by an
  explicit guard (spec/isc/semantics_spec.rb stays green).
- Re-only aliases in a reversed `to` (the boundary a word-boundary
  rule's reversal hoists onto the to side) defer the parstr build to
  match time: rs renders replacements lazily, so a rule that never
  fires must not poison the whole pass (bgnpcgn-per / un-prs "Can't
  use boundary in a par context" nulls).
- A from-pattern backreference to a group the pattern does not itself
  define drops the rule from the alternation: rs match_item fails a ref
  on an unparticipated group (never matches), while the combined
  named-group compile refused numbered refs outright (bgnpcgn-zho
  RegexpError nulls). ruby gsub semantics for unmatched/out-of-range
  refs (empty insertion) were already correct here.
@ronaldtse
ronaldtse merged commit c39b829 into main Nov 18, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant